<?php

include_once (CTRL_ROOT . 'abstractAction.php');

class AbstractSiteAction extends AbstractAction {

    //properties
    private $pageTitle;
    private $navHTML;
    private $navArray;

    //getter / setter

    public function __construct($navArray) {
        parent::__construct();
        $this->navArray = $navArray;
		$this->renderError();
    }
	
	protected function renderError(){
		if($this->isError()){
			$siteAction = $this;
			include(VIEW_ROOT . 'header.php');
			parent::renderError();
		}
	}

    private function getPageTitle() {
        $this->pageTitle = 'Kristine Unkrich - Business Developer';
        if (array_key_exists($this->page, $this->navArray))
            $this->pageTitle .= ' - ' . $this->navArray[$this->page]['viewTitle'];
    }

    private function getNavigation() {
        $this->navHTML = null;
        if (isset($this->navArray)) {
            $divMenu = '<div class="menu">' . "\n";
            $divClose = '</div>' . "\n";
            $this->navHTML = "";
            foreach (array_keys($this->navArray) as $key) {
                $this->navHTML .= $divMenu;
                if ($this->page == $key || ($key === 'motivation' && $this->page == '')) {
                    $this->navHTML .= '<span id="tab' . $this->navArray[$key]['viewTitle'] . '" title="' . $this->navArray[$key]['viewTitle'] . '">' . $this->navArray[$key]['viewTitle'] . '</span>' . "\n";
                }
                else
                    $this->navHTML .= '<a href="' . ROOT_PATH . $key . '" id="tab' . $this->navArray[$key]['viewTitle'] . '" title="' . $this->navArray[$key]['viewTitle'] . '">' . $this->navArray[$key]['viewTitle'] . '</a>' . "\n";
                $this->navHTML .= $divClose;
            }
        }
        else
            $this->navHTML = 'no nav array';
    }

    private function renderHeader() {
        $this->getPageTitle();
        $this->getNavigation();
		$siteAction = $this;
        include(VIEW_ROOT . 'header.php');
    }

    public function render($section, $mdlArr = null) {
        $this->loadMdl($section, $mdlArr);
        if (ACTIVATE_SESSION)
            session_start();
		$siteAction = $this;
        $navArray = $this->navArray;
        $this->renderHeader();
        @include (CTRL_ROOT . $section . 'Action.php');
        include (VIEW_ROOT . $section . '.php');

        $this->renderFooter();
    }

}

?>